# import xp

from lxml import etree
# from lxml import html
# etree = html.etree
#如果etree报错使用注释的方法导入


xml = """
<book>
        <id>1</id>
        <name>野花遍地香</name>
        <price>1.23</price>
        <nick>臭豆腐</nick>
        <author>
        <nick id="10086">周大强</nick>
        <nick id="10010">周芷若</nick>
        <nick class="jay">周杰伦</nick>
        <nick class="jolin">蔡依林</nick>
        <div>
        <nick>惹了</nick>
        </div>
        </author>
        <partner>
        <nick id="ppc">胖胖陈</nick>
        <nick id="ppbc">胖胖不胖</nick>
        </partner>
        <name>野花遍sss地香</name>
</book>
"""

# 
xmlObj = etree.XML(xml)
# res = xmlObj.xpath("/book/name/text()")#text()拿到文本
# res = xmlObj.xpath("/book//nick/text()")#标识所有的子孙后代  //
# res = xmlObj.xpath("/book/*/nick/text()")#标识孙子 *标识所有
# res = xmlObj.xpath("/book/*/nick[@class='jay']/text()")#  []属性筛选  @属性名字 = 值      bs4 findall(nick,attrs={"class":"jay"})
res = xmlObj.xpath("/book/partner/nick/@id")  #最后一个/标识  拿到nick里面@id属性的值 
print(xmlObj[0],"=====",res)